<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

	<link type="text/css" rel="stylesheet" href="#{request.contextPath}/resources/css/newsletters.css" />
	
	<h:form id="form_newsletter_settings">
	
	<p:growl id="growl_newsletters" globalOnly="true" autoUpdate="true" />  	
	<p:remoteCommand id="remoteCommand_search_newsletters" name="searchnewsletter" action="#{newsletterBean.search}" 
		oncomplete="document.getElementById('form_newsletter_settings:datatable_newsletters:globalFilter').focus();" update=":form_newsletter_settings"/>
	
	<p:dataTable id="datatable_newsletters" var="newsletter" value="#{newsletterBean.newsletters}" styleClass="datatable_newsletters"
		 paginator="true" rows="15" paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                 rowsPerPageTemplate="5,10,15" widgetVar="tablenewsletters" emptyMessage="#{msg.newsletters_not_found}">
	
		  <f:facet name="header">  
            <p:outputPanel id="outputPanel_table_newsletter_filter" style="float:right;">  
                <h:outputText value="#{msg.label_search}: " />  
                <p:inputText id="globalFilter" value="#{newsletterBean.keyword}" onkeyup="if (this.value.length >= 3 || this.value.length == 0 ){ searchnewsletter(); }" style="width:150px"
                	onfocus="var val=this.value; this.value=''; this.value= val;" />
            </p:outputPanel>  
        </f:facet>  
  
	
		<p:column  id="column_email">
			<f:facet name="header">
				#{msg.label_email}
			</f:facet>
			#{newsletter.email}
		</p:column>	
		
		<p:column  id="column_status" >
			<f:facet name="header">
				#{msg.label_status}
			</f:facet>
			<h:outputText id="outputText_yes" value="#{msg.label_actived}" rendered="#{newsletter.active}"/>
			<h:outputText id="outputText_no" value="#{msg.label_deactivate}" rendered="#{!newsletter.active}"/>
		</p:column>	
		

		<p:column id="column_actions" >
			<f:facet name="header">
				#{msg.label_actions}
			</f:facet>
			<h:panelGrid id="panelgrid_newsletter_actions" columns="4"  
				columnClasses="panelgrid_column,panelgrid_column,panelgrid_column,panelgrid_column">
			
				<p:commandLink id="commandbutton_edit"  styleClass="editbutton" action="#{newsletterBean.prepareUpdate}" oncomplete="editnewsletter.show()"
					update=":confirmDialog_Editnewsletter">
					<f:setPropertyActionListener target="#{newsletterBean.newsletter}" value="#{newsletter}" />
				</p:commandLink>
				
				<p:commandLink id="commandbutton_aprove" styleClass="approvebutton"
				  	rendered="#{!newsletter.active}" action="#{newsletterBean.active}" update=":form_newsletter_settings">
				  	<f:setPropertyActionListener target="#{newsletterBean.newsletter}" value="#{newsletter}" />
				</p:commandLink>
				
				<p:commandLink id="commandbutton_desactive"  styleClass="disablebutton"
					rendered="#{newsletter.active}" action="#{newsletterBean.deactivate}" update=":form_newsletter_settings">
					<f:setPropertyActionListener target="#{newsletterBean.newsletter}" value="#{newsletter}" />
				</p:commandLink>
				
				<p:commandLink id="commandbutton_delete" styleClass="deletebutton" oncomplete="deletenewsletter.show()" 
					action="#{newsletterBean.prepareDelete}" update=":form_newsletter_settings:confirmDialog_deletenewsletter">
					<f:setPropertyActionListener target="#{newsletterBean.newsletter}" value="#{newsletter}" />
				</p:commandLink>
				
			</h:panelGrid>
		</p:column>
			
	</p:dataTable>
	<p:confirmDialog id="confirmDialog_deletenewsletter" header="#{msg.label_newsletter_delete}" message="#{msg.delete_newsletter_question}" modal="true" 
		widgetVar="deletenewsletter">
			<h:panelGrid id="panelGrid_deletenewsletter" styleClass="panelGrid_editnewsletter"
				columns="2">

				<h:outputText id="outputtext_delete_newsletter_label_email" 	value="#{msg.label_email}:" />
				<h:outputText id="outputtext_delete_newsletter_label_email_value" 	value="#{newsletterBean.newsletter.email}" />

				<p:commandButton id="commandbutton_delete_newsletter"	value="#{msg.yes}" update="datatable_newsletters"
					 action="#{newsletterBean.delete}" oncomplete="deletenewsletter.hide()"/>
				<p:commandButton id="commandbutton_cancel" value="#{msg.no}"	onclick="deletenewsletter.hide()" />
			</h:panelGrid>
	</p:confirmDialog>
	</h:form>

	<p:dialog id="confirmDialog_Editnewsletter" header="#{msg.edit_newsletter}" modal="true" 
		widgetVar="editnewsletter" width="500" height="100">
		<h:form id="form_edit_newsletter">
			<h:panelGrid id="panelGrid_editnewsletter" styleClass="panelGrid_editnewsletter"
				columns="3">

				<h:outputText id="outputtext_edit_newsletter_label_email" 	value="#{msg.label_email}:" />
				<p:inputText id="outputtext_edit_newsletter_label_email_value" value="#{newsletterBean.email}" validator="emailValidator"
					onblur="if (!isValidEmail(this.value)){alert('#{msg.invalid_email}');}"  />
				<p:message for="outputtext_edit_newsletter_label_email_value" />
				
				<p:commandButton id="commandbutton_save_newsletter"	value="#{msg.label_save}" update="form_edit_newsletter :form_newsletter_settings"
					 action="#{newsletterBean.update}" oncomplete="if (closeAfterRequest(xhr, status, args)) {editnewsletter.hide();}" />
				<p:commandButton id="commandbutton_cancel" value="#{msg.label_cancel}" action="#{newsletterBean.cancelEditNewsletter}"
					onclick="editnewsletter.hide()" update=":form_newsletter_settings:datatable_newsletters" />
			</h:panelGrid>

		</h:form>
	</p:dialog>
	
	
</html>